<?php

namespace App\Http\Controllers\Goods\Order;


use App\Http\Requests\Goods\Order\OrderRequest;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use OrderSave;
use OrderShow;
use App\Jobs\Order\CloseOrder;
use App\Models\Goods\Order;
class OrdersController extends Controller
{
    public function __construct()
    {
        $this->middleware('auth');
    }
    public function index(Request $request)
    {
        $orders = OrderShow::index($request);
        return view('goods.orders.index', ['orders' => $orders]);
    }
    public function store(OrderRequest $request)
    {
        $order=OrderSave::store($request);
        $this->dispatch(new CloseOrder($order, config('app.order_ttl')));
        return $order;
    }
    public function show(Order $order, Request $request)
    {
        $this->authorize('own', $order);
        return view('goods.orders.show', ['order' => $order->load(['items.productSku', 'items.product'])]);
    }
}
